# Huawei Technologies Co.,Ltd.

set(FORTEST_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fortest.txt)
set(FORTEST_JS ${CMAKE_CURRENT_SOURCE_DIR}/fortest.js)
set(FORTEST_BIN ${CMAKE_CURRENT_BINARY_DIR}/fortest.abc)
set(FORTEST_PA ${CMAKE_CURRENT_BINARY_DIR}/fortest.pa)
set(FORTEST_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${FORTEST_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${FORTEST_OUTPUT}
    COMMENT "running javascript fortest testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${FORTEST_JS} --dump-assembly --output ${FORTEST_BIN} > ${FORTEST_PA}
    COMMAND rm -f ${FORTEST_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} > ${FORTEST_OUTPUT}
    COMMAND bash ${FORTEST_VERIFY} ${FORTEST_OUTPUT}
)
add_custom_target(fortest
    DEPENDS ${FORTEST_OUTPUT} ${FORTEST_VERIFY}
)
add_dependencies(fortest es2panda ark)
add_dependencies(ecmascript_common_tests fortest)
